package com.test.mylotterysystem.dao.Mapper;

import com.test.mylotterysystem.dao.DO.PrizeDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PrizeMapper {

    @Insert("insert into prize (name,description,price,image_url) " +
            "values (#{name},#{description},#{price},#{imageUrl})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void create(PrizeDO prizeDO);

    @Select("select count(*) from prize")
    Integer getCount();

    @Select("select * from prize order by id desc limit #{offset},#{pageSize};")
    List<PrizeDO> getPrizeList(int offset, Integer pageSize);

    @Select("<script> " +
            "select id from prize where id in" +
            " <foreach item='item' collection='prizesId' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            "</script>")
    List<Long> selectByPrizesId(List<Long> prizesId);

    @Select("<script>" +
            " select * from prize" +
            " where id in" +
            " <foreach item='item' collection='prizesId' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> getPrizeListByIds(List<Long> prizesId);
}
